import { defineStore } from 'pinia'

export const tabsStore = defineStore('tabsStore', {
    state: () => ({
        tabsList: [],
    }),
    actions: {
        addTabsList(tabs) {  
            // 添加完整的数据校验
            if (!tabs.path || this.tabsList.some(v => v.path === tabs.path)) return

            this.tabsList.push({
                path: tabs.path,
                title: tabs.meta?.title || tabs.title || '新页面',
                meta: tabs.meta || {}
            })
        },
        removeTab(path) {
            const index = this.tabsList.findIndex(item => item.path === path)
            this.tabsList.splice(index, 1)
        }
    }
})